<?php
/**
 * path of decay
 *
 * official website
 *
 * @author		Vuk Nikolic
 * @link		http://vuk.letva.org
 * @since		Version 1.0
 */

require_once ('system/application/controllers/BaseController.php');
require_once ('system/application/models/NewsModel.php');
class News extends BaseController {
	private $page;
	private $newsPerPage = 10;
	
	public function News() {
		parent::__construct ();
	}
	/**
	 * Displays the default news page. Latest $newPerPage news.
	 *
	 */
	public function index() {
		$this->archive(0);
	}
	
	/**
	 * Displays the old news, also known as archive.
	 *
	 * @param unknown_type $page
	 */
	public function archive($page) {
		$newsPerPage = $this->getParameters()->getNewsPerPage();
		$langID = $this->getParameters()->getLangID();
		$start = $page * $newsPerPage;
		$queryString = "select n.*, m.content as title, m1.content as text 
								from news n,messages m, messages m1 
								where n.langID=$langID and n.titleMsgID=m.messageID and 
										n.textMsgID=m1.messageID 
								limit $start, $this->newsPerPage";
		$query = $this->db->query($queryString);
		
		$allNews = array();
		
		foreach ($query->result() as $row) {
			$tempNews = new NewsModel();
			$tempNews->setNewsID($row->newsID);
			$tempNews->setTitle($row->title);
			$tempNews->setText($row->text);
			$tempNews->setTextMsgID($row->textMsgID);
			$tempNews->setTitleMsgID($row->titleMsgID);
			$tempNews->setUserID($row->userID);
			$tempNews->setLangID($row->langID);
			$allNews[] = $tempNews;
		}
		
		foreach ($allNews as $news) {
			echo $news->getLangID() . " -=-=- ".$news->getNewsID() . " ---- " . $news->getTitle() . " ======== " . $news->getText(). "<br />";
		}
	}
}
?>